package org.example.setup.controller;

import org.example.model.common.Result;
import org.example.model.domain.feeback.FeedbackSupplement;
import org.example.model.dto.feeback.ExpressFeebackDto;
import org.example.setup.service.FeebackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController
@RequestMapping("feedback")
public class FeebackController {

    @Autowired
    private FeebackService feebackService;

    /**
     * 添加反馈
     * @param expressFeeback
     * @return
     */
    @RequestMapping("add")
    public int insert(@RequestBody ExpressFeebackDto expressFeeback)
    {
        System.out.println(expressFeeback);
        return feebackService.add(expressFeeback);
    }

    /**
     * 根据注册ip查询反馈信息
     * @param registerIp
     * @return
     */
    @GetMapping("selectByRegisterIp/{registerIp}")
    public ExpressFeebackDto selectByRegisterIp(@PathVariable("registerIp") String registerIp){
        return feebackService.selectByRegisterIp(registerIp);
    }

    /**
     * 添加反馈补充
     * @param supplement
     * @return
     */
    @PostMapping("supplementAdd")
    public Result SupplementAdd(@RequestBody FeedbackSupplement supplement){
        int s = feebackService.supplementAdd(supplement);
        System.out.println(s);
        if(s==1){
            return Result.build(200,"反馈成功");
        }else{
            return Result.build(500,"反馈失败");
        }
    }

    /**
     * 根据反馈id查询反馈补充
     * @param fid
     * @return
     */
    @GetMapping("findSupplement/{fid}")
    public Result findSupplement(@PathVariable("fid") Long fid){
        FeedbackSupplement supplement = feebackService.findSupplement(fid);
        if(supplement!=null){
            return Result.build(200,"存在",supplement);
        }else{
            return Result.build(500,"不存在",null);
        }
    }

}
